package com.rcloud.server.sealtalk.controller;


import com.rcloud.server.sealtalk.exception.ServiceException;
import com.rcloud.server.sealtalk.manager.NetOCRManager;
import com.rcloud.server.sealtalk.model.response.APIResult;
import com.rcloud.server.sealtalk.model.response.APIResultWrap;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;


/**
 * OCR身份证识别
 */
@Api(tags = "OCR身份证识别")
@Slf4j
@RestController
@RequestMapping("/ocr/identify")
@AllArgsConstructor
public class OCRIdentifyController extends BaseController {

    private NetOCRManager ocrManager;
    /**
     * 身份证识别
     */
    @PostMapping(value = "/idCardRecognize")
    @ApiOperation(value = "身份证识别", notes = "身份证识别")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "文件", dataType = "MultipartFile"),
            @ApiImplicitParam(name = "regType", value = "识别类型 2身份证头像面 3身份证国徽面", dataType = "String")
    })
    public APIResult<Object> idCardRecognize(@RequestParam("file") MultipartFile file, String regType) throws ServiceException {
        Map<String, Object> map = ocrManager.idCardRecognizeHandle(file,regType);
        return APIResultWrap.ok(map);
    }
}